/**
 * Created by wdcy336 on 2015/7/22.
 */
Ext.define('Monkey.Utils', {
    singleton: true,

    arrayModelToString: function (array, property, delim) {
        var result = '';
        var length = array.length;
        for (var i = 0; i < length; i++) {
            result += array[i].get(property);
            if (i < length - 1) {
                result += delim;
            }
        }
        return result;
    },

    arrayToString: function (array, delim) {
        var result = '';
        var length = array.length;
        for (var i = 0; i < length; i++) {
            result += array[i];
            if (i < length - 1) {
                result += delim;
            }
        }
        return result;
    },

    request: function (url, method, params, callback) {
        Ext.Ajax.request({
            url: url,
            method: method,
            params: params,
            success: function (response) {
                var result = Ext.decode(response.responseText);
                //console.log(result);
                if (!result.success && result.responseCode == Monkey.ResponseCode.NOT_LOGIN) {
                    //进入登录页面
                    Ext.getCmp('mainView').getController().toLoginPage();
                    return;
                }
                callback(result);
            }
        });
    }

});